package com.hzw.rest;

import com.hzw.api.IShoppingCarService;
import com.hzw.entity.ShoppingCar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("shoppingCar")
public class ShoppingCarController {

    @Autowired
    IShoppingCarService shoppingCarService;

    /**
     * 添加购物车
     * @param shoppingCar
     * @return
     */
    @PostMapping("addUpdate")
    @ResponseBody
    public void addUpdate(@RequestBody ShoppingCar shoppingCar){
        shoppingCarService.addUpdate(shoppingCar);
    }
    /**
     * 添加购物车
     * @param shoppingCar
     * @return
     */
    @PostMapping("delete")
    @ResponseBody
    public int delete(@RequestBody ShoppingCar shoppingCar){
       return shoppingCarService.delByUserId(shoppingCar);
    }

    /**
     * 修改购物车
     * @param shoppingCar
     * @return
     */
    @PostMapping("update")
    @ResponseBody
    public void update(@RequestBody ShoppingCar shoppingCar){
        shoppingCarService.update(shoppingCar);
    }

    /**
     * 查询购物车信息
     * @param shoppingCar
     * @return
     */
    @PostMapping("select")
    @ResponseBody
    public List<ShoppingCar> select(@RequestBody ShoppingCar shoppingCar){
        return shoppingCarService.selectByUserId(shoppingCar);
    }
}
